package com.acme.task3;

import java.io.Console;

/**
 * This class implements 3 methods: question1(), question2() and question3() for
 * 3 questions of third task correspondently
 * 
 * @author Anton Kotov
 */
public class Task3Arrays {
	private static int[] array;

	private static void question1() {
		for (int i = 1; i <= 50; i++) {
			System.out.println(i);
		}
	}

	private static void question2() {
		for (int i = 1; i <= 50; i++) {
			if (i % 3 == 0) {
				System.out.format("number %d is a multiple of three%n", i);
			}
		}
	}

	private static void question3() {
		Console con = System.console();
		if (con == null) {
			return;
		}

		int n = Integer.parseInt(con.readLine("Input count of elements n: "));
		array = new int[n];
		for (int i = 0; i < n; array[i] = i + 1, i++)
			;
		System.out.println("Avg value of array is " + avg());
	}

	/**
	 * This method return average value of array
	 * 
	 * @return average value of array
	 */
	private static double avg() {
		if (array == null || array.length == 0) {
			return 0.;
		}

		double sum = 0.;
		for (int i = 0; i < array.length; sum += array[i], i++)
			;
		return sum /= array.length;
	}

	/**
	 * Main method
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		question1();
		question2();
		try {
			question3();
		} catch (NumberFormatException e) {

		}
	}
}
